{
 "cells": [
  {
   "cell_type": "code",
   "execution_count": 2,
   "id": "ff6234a9",
   "metadata": {},
   "outputs": [],
   "source": [
    "import numpy as np\n",
    "import pandas as pd\n",
    "from pandas import Series,DataFrame"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 3,
   "id": "67df9e21",
   "metadata": {},
   "outputs": [],
   "source": [
    "raw_data ={'单价': [3398, 1599, 4899, 2199], '商品名称': ['电脑', '手机', '智能电视', '冰箱'], '销量': [72000, 120000, 40700, 31200]}"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 6,
   "id": "cb871157",
   "metadata": {},
   "outputs": [],
   "source": [
    "data = DataFrame(raw_data, columns=['商品名称','单价','销量'])"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 7,
   "id": "9feca076",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/html": [
       "<div>\n",
       "<style scoped>\n",
       "    .dataframe tbody tr th:only-of-type {\n",
       "        vertical-align: middle;\n",
       "    }\n",
       "\n",
       "    .dataframe tbody tr th {\n",
       "        vertical-align: top;\n",
       "    }\n",
       "\n",
       "    .dataframe thead th {\n",
       "        text-align: right;\n",
       "    }\n",
       "</style>\n",
       "<table border=\"1\" class=\"dataframe\">\n",
       "  <thead>\n",
       "    <tr style=\"text-align: right;\">\n",
       "      <th></th>\n",
       "      <th>商品名称</th>\n",
       "      <th>单价</th>\n",
       "      <th>销量</th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th>0</th>\n",
       "      <td>电脑</td>\n",
       "      <td>3398</td>\n",
       "      <td>72000</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>1</th>\n",
       "      <td>手机</td>\n",
       "      <td>1599</td>\n",
       "      <td>120000</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2</th>\n",
       "      <td>智能电视</td>\n",
       "      <td>4899</td>\n",
       "      <td>40700</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>3</th>\n",
       "      <td>冰箱</td>\n",
       "      <td>2199</td>\n",
       "      <td>31200</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "</div>"
      ],
      "text/plain": [
       "   商品名称    单价      销量\n",
       "0    电脑  3398   72000\n",
       "1    手机  1599  120000\n",
       "2  智能电视  4899   40700\n",
       "3    冰箱  2199   31200"
      ]
     },
     "execution_count": 7,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "data"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 8,
   "id": "d543221a",
   "metadata": {},
   "outputs": [],
   "source": [
    "data['销售额'] = data['单价']*data['销量']"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 9,
   "id": "3c14643d",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/html": [
       "<div>\n",
       "<style scoped>\n",
       "    .dataframe tbody tr th:only-of-type {\n",
       "        vertical-align: middle;\n",
       "    }\n",
       "\n",
       "    .dataframe tbody tr th {\n",
       "        vertical-align: top;\n",
       "    }\n",
       "\n",
       "    .dataframe thead th {\n",
       "        text-align: right;\n",
       "    }\n",
       "</style>\n",
       "<table border=\"1\" class=\"dataframe\">\n",
       "  <thead>\n",
       "    <tr style=\"text-align: right;\">\n",
       "      <th></th>\n",
       "      <th>商品名称</th>\n",
       "      <th>单价</th>\n",
       "      <th>销量</th>\n",
       "      <th>销售额</th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th>0</th>\n",
       "      <td>电脑</td>\n",
       "      <td>3398</td>\n",
       "      <td>72000</td>\n",
       "      <td>244656000</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>1</th>\n",
       "      <td>手机</td>\n",
       "      <td>1599</td>\n",
       "      <td>120000</td>\n",
       "      <td>191880000</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2</th>\n",
       "      <td>智能电视</td>\n",
       "      <td>4899</td>\n",
       "      <td>40700</td>\n",
       "      <td>199389300</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>3</th>\n",
       "      <td>冰箱</td>\n",
       "      <td>2199</td>\n",
       "      <td>31200</td>\n",
       "      <td>68608800</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "</div>"
      ],
      "text/plain": [
       "   商品名称    单价      销量        销售额\n",
       "0    电脑  3398   72000  244656000\n",
       "1    手机  1599  120000  191880000\n",
       "2  智能电视  4899   40700  199389300\n",
       "3    冰箱  2199   31200   68608800"
      ]
     },
     "execution_count": 9,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "data"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 18,
   "id": "c90b4f20",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/html": [
       "<div>\n",
       "<style scoped>\n",
       "    .dataframe tbody tr th:only-of-type {\n",
       "        vertical-align: middle;\n",
       "    }\n",
       "\n",
       "    .dataframe tbody tr th {\n",
       "        vertical-align: top;\n",
       "    }\n",
       "\n",
       "    .dataframe thead th {\n",
       "        text-align: right;\n",
       "    }\n",
       "</style>\n",
       "<table border=\"1\" class=\"dataframe\">\n",
       "  <thead>\n",
       "    <tr style=\"text-align: right;\">\n",
       "      <th></th>\n",
       "      <th>商品名称</th>\n",
       "      <th>销售额</th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th>0</th>\n",
       "      <td>电脑</td>\n",
       "      <td>244656000</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>3</th>\n",
       "      <td>冰箱</td>\n",
       "      <td>68608800</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "</div>"
      ],
      "text/plain": [
       "  商品名称        销售额\n",
       "0   电脑  244656000\n",
       "3   冰箱   68608800"
      ]
     },
     "execution_count": 18,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "index = (data[\"商品名称\"]==\"电脑\")|(data[\"商品名称\"]==\"冰箱\")\n",
    "data.loc[index,[\"商品名称\",\"销售额\"]]"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 19,
   "id": "cfba8022",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/html": [
       "<div>\n",
       "<style scoped>\n",
       "    .dataframe tbody tr th:only-of-type {\n",
       "        vertical-align: middle;\n",
       "    }\n",
       "\n",
       "    .dataframe tbody tr th {\n",
       "        vertical-align: top;\n",
       "    }\n",
       "\n",
       "    .dataframe thead th {\n",
       "        text-align: right;\n",
       "    }\n",
       "</style>\n",
       "<table border=\"1\" class=\"dataframe\">\n",
       "  <thead>\n",
       "    <tr style=\"text-align: right;\">\n",
       "      <th></th>\n",
       "      <th>单价</th>\n",
       "      <th>销量</th>\n",
       "      <th>销售额</th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th>2</th>\n",
       "      <td>4899</td>\n",
       "      <td>40700</td>\n",
       "      <td>199389300</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>3</th>\n",
       "      <td>2199</td>\n",
       "      <td>31200</td>\n",
       "      <td>68608800</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "</div>"
      ],
      "text/plain": [
       "     单价     销量        销售额\n",
       "2  4899  40700  199389300\n",
       "3  2199  31200   68608800"
      ]
     },
     "execution_count": 19,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "data.iloc[2:,1:]"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 20,
   "id": "1d487645",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/html": [
       "<div>\n",
       "<style scoped>\n",
       "    .dataframe tbody tr th:only-of-type {\n",
       "        vertical-align: middle;\n",
       "    }\n",
       "\n",
       "    .dataframe tbody tr th {\n",
       "        vertical-align: top;\n",
       "    }\n",
       "\n",
       "    .dataframe thead th {\n",
       "        text-align: right;\n",
       "    }\n",
       "</style>\n",
       "<table border=\"1\" class=\"dataframe\">\n",
       "  <thead>\n",
       "    <tr style=\"text-align: right;\">\n",
       "      <th></th>\n",
       "      <th>商品名称</th>\n",
       "      <th>单价</th>\n",
       "      <th>销量</th>\n",
       "      <th>销售额</th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th>0</th>\n",
       "      <td>电脑</td>\n",
       "      <td>3398</td>\n",
       "      <td>72000</td>\n",
       "      <td>244656000</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2</th>\n",
       "      <td>智能电视</td>\n",
       "      <td>4899</td>\n",
       "      <td>40700</td>\n",
       "      <td>199389300</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>3</th>\n",
       "      <td>冰箱</td>\n",
       "      <td>2199</td>\n",
       "      <td>31200</td>\n",
       "      <td>68608800</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "</div>"
      ],
      "text/plain": [
       "   商品名称    单价     销量        销售额\n",
       "0    电脑  3398  72000  244656000\n",
       "2  智能电视  4899  40700  199389300\n",
       "3    冰箱  2199  31200   68608800"
      ]
     },
     "execution_count": 20,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "data[data[\"单价\"]>2000]"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 21,
   "id": "750b43a4",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/html": [
       "<div>\n",
       "<style scoped>\n",
       "    .dataframe tbody tr th:only-of-type {\n",
       "        vertical-align: middle;\n",
       "    }\n",
       "\n",
       "    .dataframe tbody tr th {\n",
       "        vertical-align: top;\n",
       "    }\n",
       "\n",
       "    .dataframe thead th {\n",
       "        text-align: right;\n",
       "    }\n",
       "</style>\n",
       "<table border=\"1\" class=\"dataframe\">\n",
       "  <thead>\n",
       "    <tr style=\"text-align: right;\">\n",
       "      <th></th>\n",
       "      <th>商品名称</th>\n",
       "      <th>单价</th>\n",
       "      <th>销量</th>\n",
       "      <th>销售额</th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th>2</th>\n",
       "      <td>智能电视</td>\n",
       "      <td>4899</td>\n",
       "      <td>40700</td>\n",
       "      <td>199389300</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>0</th>\n",
       "      <td>电脑</td>\n",
       "      <td>3398</td>\n",
       "      <td>72000</td>\n",
       "      <td>244656000</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>3</th>\n",
       "      <td>冰箱</td>\n",
       "      <td>2199</td>\n",
       "      <td>31200</td>\n",
       "      <td>68608800</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>1</th>\n",
       "      <td>手机</td>\n",
       "      <td>1599</td>\n",
       "      <td>120000</td>\n",
       "      <td>191880000</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "</div>"
      ],
      "text/plain": [
       "   商品名称    单价      销量        销售额\n",
       "2  智能电视  4899   40700  199389300\n",
       "0    电脑  3398   72000  244656000\n",
       "3    冰箱  2199   31200   68608800\n",
       "1    手机  1599  120000  191880000"
      ]
     },
     "execution_count": 21,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "data.sort_values(by='单价',ascending=False)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "723db3d2",
   "metadata": {},
   "outputs": [],
   "source": []
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "63f39e0d",
   "metadata": {},
   "outputs": [],
   "source": []
  }
 ],
 "metadata": {
  "kernelspec": {
   "display_name": "Python 3 (ipykernel)",
   "language": "python",
   "name": "python3"
  },
  "language_info": {
   "codemirror_mode": {
    "name": "ipython",
    "version": 3
   },
   "file_extension": ".py",
   "mimetype": "text/x-python",
   "name": "python",
   "nbconvert_exporter": "python",
   "pygments_lexer": "ipython3",
   "version": "3.11.4"
  },
  "toc": {
   "base_numbering": 1,
   "nav_menu": {},
   "number_sections": true,
   "sideBar": true,
   "skip_h1_title": false,
   "title_cell": "Table of Contents",
   "title_sidebar": "Contents",
   "toc_cell": false,
   "toc_position": {},
   "toc_section_display": true,
   "toc_window_display": false
  }
 },
 "nbformat": 4,
 "nbformat_minor": 5
}
